/**
 * Created by wsx on 2017/5/7.
 */
//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
layui.use(['element','form','laydate','layer','laypage'], function () {
    var $ = layui.jquery;
    // var form = layui.form();
    // var element = layui.element();
    // var laydate = layui.laydate;
    // var layer = layui.layer;
    // var laypage = layui.laypage;
    // //全选
    // form.on('checkbox(allChoose)', function(data){
    //     var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
    //     child.each(function(index, item){
    //         item.checked = data.elem.checked;
    //     });
    //     form.render('checkbox');
    // });
    // form.on('submit(update-purchase)', function(data){
    //     console.log('hello');
    // });

    var active = {
        detail : function (othis) {
            //弹出即全屏
            var index = layer.open({
                type: 2,
                title: "退货详情",
                shadeClose: true,
                content: '/admin/returngoodsdetail?id='+othis.id,
                area: ['100%', '100%'],
                maxmin: false
            });
            layer.full(index);
        },
        // done : function (othis) {
        //     layer.confirm('确定将该订单标志为完成？', {
        //         icon: 3,
        //         skin: 'layui-layer-molv'
        //     },function (index) {
        //         $.ajax({
        //             url:'/donePurchase',
        //             type: 'post',
        //             dataType: 'json',
        //             data:{id : othis.pid},
        //             success: function (data) {
        //                 if (data === "修改成功！") {
        //                     window.location.href = "/admin/purchase/lists";
        //                 }
        //                 layer.msg(data);
        //             }
        //         });
        //         layer.close(index);
        //     })
        // },
        delete : function (othis) {
            //删除
            layer.open({
                type: 1,
                title: false, //不显示标题栏
                closeBtn: false,
                area: '300px;',
                shade: 0.8,
                id: 'LAY_layuipro', //设定一个id，防止重复弹出
                btn: ['绝不后悔', '我怂了'],
                moveType: 1, //拖拽模式，0或者1,
                content: '<div style="padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">删除后将不可恢复，是否确认删除<br></div>',
                yes: function (index, layero) {
                    $.ajax({
                        url: "/deletereturngoods.action",
                        type: 'post',
                        data: {
                           id: othis.id
                        },
                        dataType: 'json',
                        success: function (data) {
                            if (data === "删除成功！") {
                                window.location.href = "/admin/applyreturngoods";
                            }
                            layer.msg(data);
                        }
                    });
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                }
            });
        }
    };
    $('.edit').on('click', function () {
        var othis = $(this), method = othis.data('method');
        othis.id = $(this).attr('id');
        active[method] ? active[method].call(this, othis) : '';
    });
    // $('.done').on('click', function () {
    //     var othis = $(this), method = othis.data('method');
    //     othis.pid = $(this).attr('pid');
    //     active[method] ? active[method].call(this, othis) : '';
    // });
    $('.delete').on('click', function () {
        var othis = $(this), method = othis.data('method');
        othis.id = $(this).attr('id');
        active[method] ? active[method].call(this, othis) : '';
    });

});
layui.use(['laypage', 'layer'], function(){
    var laypage = layui.laypage,layer = layui.layer;

    laypage({
        cont: 'fullpage',
        pages: $('#pageCount').val(), //分页总数
        skip: true,
        curr: $('#pageIndex').val(),
        jump: function(obj, first) {
            if (first != true) {//是否首次进入页面
                var pageIndex = obj.curr;//获取点击的页码
                var jsonObject = $('#jsonObject').val();
                if (jsonObject.length > 0) {
                    console.log(jsonObject);
                    var objs = eval('(' + jsonObject + ')');//将json转成对象
                    var condition = 'pageIndex=' + pageIndex + '&';
                    condition += "croReturngoodsVo.username=" + objs.username + '&' + "croReturngoodsVo.purchaseid=" + objs.purchaseid + '&' + "croReturngoodsVo.returnstatus=" + objs.returnstatus;
                    console.log(condition);
                    window.location.href = "/admin/findreturngoods?" + condition;
                } else {
                    window.location.href = "/admin/applyreturngoods?pageIndex=" + pageIndex;
                }
            }
        }
    });
});